package com.example.demo1;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity
{
	private final static String TAG = BuildConfig.DEBUG ? MainActivity.class.getSimpleName() : null;
	
	View mRoot;
	KAnimationLayout animLayout1;
	KAnimationLayout animLayout2;
	KAnimationLayout animLayout3;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		mRoot = View.inflate(this, R.layout.activity_main, null);
		setContentView(mRoot);
		init();
	}
	
	private void init()
	{
		animLayout1 = (KAnimationLayout) mRoot.findViewById(R.id.anim_layout1);
		animLayout2 = (KAnimationLayout) mRoot.findViewById(R.id.anim_layout2);
		animLayout3 = (KAnimationLayout) mRoot.findViewById(R.id.anim_layout3);
//		
		final TextView text1 = (TextView) mRoot.findViewById(R.id.text1);
		final TextView text2 = (TextView) mRoot.findViewById(R.id.text2);
		final TextView text3 = (TextView) mRoot.findViewById(R.id.text3);
		
		Button btn1 = (Button) findViewById(R.id.button1);
		Button btn2 = (Button) mRoot.findViewById(R.id.button2);
		Button btn3 = (Button) mRoot.findViewById(R.id.button3);
		
		btn1.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Log.d(TAG, "btn1 onClick");
				changeAnimLayout(animLayout1, text1);
			}
		});
		btn2.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				// TODO Auto-generated method stub
				changeAnimLayout(animLayout2, text2);
			}
		});
		btn3.setOnClickListener(new OnClickListener()
		{
			
			@Override
			public void onClick(View v)
			{
				// TODO Auto-generated method stub
				changeAnimLayout(animLayout3, text3);
			}
		});
		
		text1.setOnClickListener(new OnClickListener()
		{
			
			@Override
			public void onClick(View v)
			{
				startActivity(new Intent(MainActivity.this, PopupWindowKAnimationTest.class));
			}
		});
		
	}

	private void changeAnimLayout(KAnimationLayout layout, final TextView text)
	{
		if (!layout.isExpanded())
		{
			text.setVisibility(View.VISIBLE);
			layout.expandAnimation(new Runnable()
			{
				public void run()
				{
				}
			});
		}
		else
		{
			layout.shrinkAnimation(new Runnable()
			{
				public void run()
				{
					text.setVisibility(View.GONE);
				}
			});
		}
	}
}
